package com.dayu.recovery.domain.export;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dayu.common.annotation.Excel;
import com.dayu.system.service.ISysDictDataService;
import com.dayu.utils.constant.OptionsConstant;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 财务账单与报价账单
 */
public class BillAndCollectExport {

    /** 商品编码 */
    @Excel(name = "商品编码")
    private String goodsId;

    @Excel(name = "仓库名称")
    private String stockName;

    /** 账单名称 */
    @Excel(name = "账单名称")
    private String billName;

    /** 商品串号 */
    @Excel(name = "商品串号")
    private String goodsSn;

    /** 成本价 */
    @Excel(name = "成本价")
    private BigDecimal costPrice;

    /** 销售价 */
    @Excel(name = "销售价")
    private BigDecimal sellPrice;

    /** 利润 */
    @Excel(name = "利润")
    private BigDecimal profit;

    /** 买家 */
    @Excel(name = "买家")
    private String buyers;

    @Excel(name = "收款账单", dictType = "recovery_bill_payee")
    private String payee;
    /** 支付方式 */
    @Excel(name = "支付方式", readConverterExp = "1=支付宝,2=微信,3=现金,4=多种支付,5=旧机抵扣,6=银行卡")
    private Integer paymentType;

    @Excel(name = "支付详情")
    private String paymentDetail;

    /** 状态 */
    @Excel(name = "状态", readConverterExp = "1=待审核,2=已审核,3=退货,4=作废")
    private Integer status;

    /** 类型 */
    @Excel(name = "类型", readConverterExp = "1=商品出售,2=自定义账单,3=退货账单")
    private Integer type;

    @Excel(name = "销售人")
    private String sellBy;

    /** 创建人 */
    private Long createId;
    @Excel(name = "创建人")
    private String createBy;

    @Excel(name = "创建时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Excel(name = "更新人")
    private String updateBy;

    @Excel(name = "更新时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @Excel(name = "最后验机人")
    private String testUserName;

    private String nowTestName;

    @Excel(name = "供应商")
    private String supplierName;

    @Excel(name = "配送类型", dictType = "recovery_bill_give_type")
    private Integer giveType;

    @Excel(name = "配送单号")
    private String giveNumber;

    @Excel(name = "配送费用")
    private BigDecimal givePrice;

    @Excel(name = "配件信息")
    private String partsInfo;

    @Excel(name = "配件金额")
    private BigDecimal partsPrice;

    @Excel(name = "回收编号")
    private Long storeId;

    @Excel(name = "报价师", dictType = "dayu_offer_teach")
    private String offerName;

    /** 机型名称 */
    private String modelName;

    /** 机型串号 */
    private String modelSn;

    /* 公司信息*/
    @Excel(name = "公司信息")
    private String companyInfo;

    private String company;
    private String storeName;
    private String checkName;

    private BigDecimal price;

    /** 返利一 */
    private BigDecimal priceOne;

    /** 返利二 */
    private BigDecimal priceTwo;

    /** 返利三 */
    private BigDecimal priceThree;

    private BigDecimal totalPrice;

    /** 转账方式 */
    private Integer tranType;

    /** 转账人 */
    private String tranName;

    /** 报价时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date offerTime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date collectTime;

    @Excel(name = "生成时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date createTimeByGood;

    public String getPartsInfo() {
        return partsInfo;
    }

    public void setPartsInfo(String partsInfo) {
        this.partsInfo = partsInfo;
    }

    public BigDecimal getPartsPrice() {
        return partsPrice;
    }

    public void setPartsPrice(BigDecimal partsPrice) {
        this.partsPrice = partsPrice;
    }

    public Date getCreateTimeByGood() {
        return createTimeByGood;
    }

    public void setCreateTimeByGood(Date createTimeByGood) {
        this.createTimeByGood = createTimeByGood;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public String getStockName() {
        return stockName;
    }

    public void setStockName(String stockName) {
        this.stockName = stockName;
    }

    public String getBillName() {
        return billName;
    }

    public void setBillName(String billName) {
        this.billName = billName;
    }

    public String getGoodsSn() {
        return goodsSn;
    }

    public void setGoodsSn(String goodsSn) {
        this.goodsSn = goodsSn;
    }

    public BigDecimal getCostPrice() {
        return costPrice;
    }

    public void setCostPrice(BigDecimal costPrice) {
        this.costPrice = costPrice;
    }

    public BigDecimal getSellPrice() {
        return sellPrice;
    }

    public void setSellPrice(BigDecimal sellPrice) {
        this.sellPrice = sellPrice;
    }

    public BigDecimal getProfit() {
        return profit;
    }

    public void setProfit(BigDecimal profit) {
        this.profit = profit;
    }

    public String getBuyers() {
        return buyers;
    }

    public void setBuyers(String buyers) {
        this.buyers = buyers;
    }

    public String getPayee() {
        return payee;
    }

    public void setPayee(String payee) {
        this.payee = payee;
    }

    public Integer getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(Integer paymentType) {
        this.paymentType = paymentType;
    }

    public String getPaymentDetail() {
        return paymentDetail;
    }

    public void setPaymentDetail(String paymentDetail) {
        this.paymentDetail = paymentDetail;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getSellBy() {
        return sellBy;
    }

    public void setSellBy(String sellBy) {
        this.sellBy = sellBy;
    }

    public Long getCreateId() {
        return createId;
    }

    public void setCreateId(Long createId) {
        this.createId = createId;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getTestUserName() {
        return testUserName;
    }

    public void setTestUserName(String testUserName) {
        this.testUserName = testUserName;
    }

    public String getNowTestName() {
        return nowTestName;
    }

    public void setNowTestName(String nowTestName) {
        this.nowTestName = nowTestName;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public Integer getGiveType() {
        return giveType;
    }

    public void setGiveType(Integer giveType) {
        this.giveType = giveType;
    }

    public String getGiveNumber() {
        return giveNumber;
    }

    public void setGiveNumber(String giveNumber) {
        this.giveNumber = giveNumber;
    }

    public BigDecimal getGivePrice() {
        return givePrice;
    }

    public void setGivePrice(BigDecimal givePrice) {
        this.givePrice = givePrice;
    }

    public Long getStoreId() {
        return storeId;
    }

    public void setStoreId(Long storeId) {
        this.storeId = storeId;
    }

    public String getOfferName() {
        return offerName;
    }

    public void setOfferName(String offerName) {
        this.offerName = offerName;
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getModelSn() {
        return modelSn;
    }

    public void setModelSn(String modelSn) {
        this.modelSn = modelSn;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public String getCheckName() {
        return checkName;
    }

    public void setCheckName(String checkName) {
        this.checkName = checkName;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getPriceOne() {
        return priceOne;
    }

    public void setPriceOne(BigDecimal priceOne) {
        this.priceOne = priceOne;
    }

    public BigDecimal getPriceTwo() {
        return priceTwo;
    }

    public void setPriceTwo(BigDecimal priceTwo) {
        this.priceTwo = priceTwo;
    }

    public BigDecimal getPriceThree() {
        return priceThree;
    }

    public void setPriceThree(BigDecimal priceThree) {
        this.priceThree = priceThree;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Integer getTranType() {
        return tranType;
    }

    public void setTranType(Integer tranType) {
        this.tranType = tranType;
    }

    public String getTranName() {
        return tranName;
    }

    public void setTranName(String tranName) {
        this.tranName = tranName;
    }

    public Date getOfferTime() {
        return offerTime;
    }

    public void setOfferTime(Date offerTime) {
        this.offerTime = offerTime;
    }

    public Date getCollectTime() {
        return collectTime;
    }

    public void setCollectTime(Date collectTime) {
        this.collectTime = collectTime;
    }

    public String getCompanyInfo() {
        return companyInfo;
    }

    public void setCompanyInfo(String companyInfo) {
        this.companyInfo = companyInfo;
    }

    public void tranPaymentDetailExcl(ISysDictDataService dataService) {
        if(ObjectUtils.isEmpty(this.paymentDetail)) {
            return;
        }
        String resStr = "";
        if(getPaymentType() == 4) {
            JSONArray paymentArr = JSONArray.parseArray(this.paymentDetail);
            for(int i = 0; i < paymentArr.size(); i++) {
                JSONObject map = JSON.parseObject(paymentArr.get(i).toString());
                String type = OptionsConstant.getPaymentDetail(map.get("type").toString());
                String payee = map.get("payee") != null ?
                        dataService.selectDictLabel("recovery_bill_payee", map.get("payee").toString()) : "";
                resStr += "[" + type + " " +  map.get("price") + " " + payee + "]";
            }
        }else if(getPaymentType() == 6) {
            JSONObject a = JSONObject.parseObject(this.paymentDetail);
            if(a.get("number") != null) {
                resStr = a.get("number").toString();
            }
        }

        this.paymentDetail = resStr;
    }

    public void totalPriceAdd() {
        if(!ObjectUtils.isEmpty(price)) {
            totalPrice = price;
        }
        if(!ObjectUtils.isEmpty(priceOne)) {
            totalPrice = totalPrice.add(priceOne);
        }
        if(!ObjectUtils.isEmpty(priceTwo)) {
            totalPrice = totalPrice.add(priceTwo);
        }
        if(!ObjectUtils.isEmpty(priceThree)) {
            totalPrice = totalPrice.add(priceThree);
        }
    }

    public void setExportCompany() {
        if(StringUtils.isEmpty(companyInfo)) {
            return;
        }
        String[] arr = companyInfo.split(" ");
        switch (arr.length) {
            case 1 : company = arr[0];break;
            case 2 : company = arr[0]; storeName = arr[1];break;
            case 3 : company = arr[0]; storeName = arr[1]; checkName = arr[2];break;
        }
    }
}
